<template>
<div class="personal">
	<Button type="primary" @click="personalSave">保存</Button><br><br>
<Row>
<Col span="8">
	<Form ref="form" :model="baseform"  :label-width="80">
		<FormItem label="登录工号" prop="uid">
			<Input v-model="baseform.uid" disabled></Input>
		</FormItem>
		<FormItem label="姓名" prop="uname">
			<Input v-model="baseform.uname" disabled></Input>
		</FormItem>
		<FormItem label="部门" prop="dept">
			<Input v-model="baseform.dept" disabled></Input>
		</FormItem>
		<FormItem label="电话" prop="phone">
			<Input v-model="baseform.phone" disabled></Input>
		</FormItem>
		<FormItem label="性别" prop="sex">
			<RadioGroup v-model="baseform.sex">
				<Radio label="男"></Radio>
				<Radio label="女"></Radio>
			</RadioGroup>
		</FormItem>
		<FormItem label="执法证号" prop="certificate">
			<Input v-model="baseform.certificate"></Input>
		</FormItem>
		<FormItem label="个人签名" prop="sign">
			<Upload ref="upload" :show-upload-list="false" :on-success="handleSuccess" 
			:format="['jpg','jpeg','png']" :max-size="20480" type="drag" 
			name="file" style="display: inline-block;width:100%;" :data="{uid:baseform.uid}"
			:action="uploadAction">
			    <div style="width: 100%;height:128px;line-height: 128px;">
			        <Icon type="ios-camera" size="24" v-if="baseform.sign==null"></Icon>
			        <img :src="signURL" height="128" v-else>
			    </div>
			</Upload>
		</FormItem>
	</Form>
</Col>
</Row>
</div>
</template>

<script>
import { Input } from 'view-ui-plus'
import config from '@/config'
export default {
	data(){
		return {	
			signChange:false,
			baseform:{}
		}
	},
	computed:{
		uploadAction(){
			return config.baseUrl+'tangyin/main/personalUploadSign.action'
		},
		signURL(){
			return config.baseUrl+this.baseform.sign
		}
	},
	methods:{
		handleSuccess(response, file, fileList){
			this.baseform.sign=response
			this.signChange=true
		},
		personalSave(){
			if(this.signChange){
				this.$axios.post('checkVcode.action',{str1:this.$store.state.user.userInfo.phone}).then(res=>{
					this.$Modal.confirm({
						title: '更换签名身份确认',
						render: (h) => {
							return h( Input, {
								size: "large",modelValue: '',placeholder: '请输入手机短信验证码',
								'onInput': (event) => {
									this.baseform.vcode = event.target.value
								}
							})
						},
						onOk: () => {
							if(this.baseform.vcode==res.data){
								this.$axios.post('personalSaveInfo.action',this.baseform).then(res=>{
									this.$Message.success('保存成功')
									//this.$router.push({ name: 'HomeView' })
								})
							}else{
								this.$Notice.error({title: '验证码错误，请重新获取'})
							}
						}
					})
				})
			}else{
				delete this.baseform.sign
				this.$axios.post('personalSaveInfo.action',this.baseform).then(res=>{
					this.$Message.success('保存成功')
					//this.$router.push({ name: 'HomeView' })
				})
			}
		}
	},
	mounted() {
		this.baseform={...this.$store.state.user.userInfo}
	}
}
</script>

<style>
.personal{
	padding:16px ;
}
</style>